package com.oim.function.ui;

import java.util.List;

import com.oim.fx.ui.BaseFrame;
import com.oim.fx.ui.component.WaitingPanel;

import javafx.geometry.Insets;
import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.control.Pagination;
import javafx.scene.control.ScrollPane;
import javafx.scene.layout.Background;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.scene.text.Font;
import javafx.util.Callback;

/**
 * 设备列表
 * 
 * @author: XiaHui
 * @date: 2017年4月11日 上午9:02:43
 */
public class DeviceListFrame extends BaseFrame {

	Pagination page = new Pagination();// 分页组件
	StackPane centerPane = new StackPane();
	FlowPane flowPane = new FlowPane();
	WaitingPanel waitingPanel = new WaitingPanel();
	ScrollPane scrollPane = new ScrollPane();
	public DeviceListFrame() {
		initComponent();
		iniEvent();
	}

	private void initComponent() {
		this.setTitle("设备列表");
		this.setResizable(false);
		this.setWidth(960);
		this.setHeight(600);
		this.setTitlePaneStyle(2);
		this.setRadius(5);
		BorderPane rootPane = new BorderPane();
		this.setCenter(rootPane);

		Label titleLabel = new Label();
		titleLabel.setText("设备列表");
		titleLabel.setFont(Font.font("微软雅黑", 30));
		titleLabel.setStyle("-fx-text-fill:rgba(255, 255, 255, 1)");

		HBox hBox = new HBox();
		hBox.setMinHeight(35);
		hBox.setStyle("-fx-background-color:rgba(18, 98, 217, 1)");
		
		hBox.getChildren().add(titleLabel);
		
		
		
//		VBox rootBox = new VBox();
//		rootBox.getChildren().add(centerPane);

		flowPane.setPadding(new Insets(15, 10, 0, 10));
		flowPane.setVgap(10);	
		flowPane.setHgap(10);	
		flowPane.setPrefWrapLength(920); // 预设流面板的宽度，使得能够显示两列
		
		
		scrollPane.setBackground(Background.EMPTY);
        scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
        scrollPane.setContent(flowPane);
        
		centerPane.getChildren().add(scrollPane);
		centerPane.getChildren().add(waitingPanel);

		centerPane.setStyle("-fx-background-color:rgba(8, 103, 68, 0.5)");
		
		rootPane.setTop(hBox);
		rootPane.setCenter(centerPane);
		rootPane.setBottom(page);
		rootPane.setStyle("-fx-background-color:rgba(255, 255, 255, 0.5)");
		
		this.showWaiting(false, WaitingPanel.show_waiting);
		this.setPage(0, 1);
	}

	private void iniEvent() {
		// TODO Auto-generated method stub
	}

	public void showWaiting(boolean show,String key) {
		waitingPanel.setVisible(show);
		flowPane.setVisible(!show);
		waitingPanel.show(key);
	}

	public void setNodeList(List<? extends Node> nodeList) {
		flowPane.getChildren().clear();
		flowPane.getChildren().addAll(nodeList);
	}

	public void setPage(int currentPage, int totalPage) {
		page.setCurrentPageIndex(currentPage);
		page.setPageCount(totalPage);
	}
	
	public void setTotalPage(int totalPage) {
		page.setPageCount(totalPage);
	}


	public void setPageFactory(Callback<Integer, Node> value) {
		page.setPageFactory(value);
		// page.setPageFactory(new Callback<Integer, Node>() {
		//
		// @Override
		// public Node call(Integer index) {
		// System.out.println(index);
		// return new Label("第" + index + "页");
		// }
		// });
	}
}
